const affirm_order = require("express").Router()
const sqlOptions = require("../../sql");


// 列表查询
affirm_order.get("/list", async (req, res) => {
    try {
        const user_id = req.rows.id

        const list = await req.db.query(sqlOptions({
            name: "oms_shopping_order",
            method: "list",
            data: {
                user_id
            }
        }))

        if (list.length) {
            return res.status(200).send({
                code: 200,
                message: "",
                data: list.map(item => {
                    delete item.id
                    return item
                })
            })
        }
        return res.status(200).send({
            code: 400,
            message: "没有确认订单,请前往购物车页面结算",
            data: ""
        })

    } catch (e) {
        return res.status(500).send({
            code: 500,
            message: "系统错误",
            data: ""
        })
    }
})

module.exports = affirm_order